package com.main.tabletobean;

import com.main.util.FileReadOrSave;
import com.main.util.StringUtil;
import com.main.util.template.ControllerTemplateUtil;
import com.main.util.template.DaoTemplateUtil;
import com.main.util.template.JspTemplateUtil;
import com.main.util.template.ServiceTemplateUtil;

public class Test {
	
	public static void main(String[] args) {
		 //System.out.println(TableToBean.class.getResource("/").toString().substring(6)+"config/");	
//			System.out.println(File.pathSeparator+" "+File.separator);
	     //String count=TableToBean.getClass("com.test.bean","QuartzTask","quartz_task");
	     FileReadOrSave frs=new FileReadOrSave();
	     
	     MyFreeMarkTemplate mfmt=new MyFreeMarkTemplate();
//	     mfmt.setTableName("quartz_task");
//	     mfmt.setTablePKSeq("QUARTZ_TASK_SEQ");
//	     mfmt.setBeanName("QuartzTask");
//	     mfmt.setPackageBean("com.test.bean");
//	     mfmt.setColumnList(TableToBean.getTableStructure(mfmt.getTableName()));
//	     
//	     DaoTemplateUtil du=new DaoTemplateUtil();
//	     ServiceTemplateUtil su=new ServiceTemplateUtil();
//	     ControllerTemplateUtil cu=new ControllerTemplateUtil();
//	     JspTemplateUtil ju=new JspTemplateUtil();
//   	     frs.saveFileContent("D:/workspace_new/WebServicesPlatForm/src/com/test/bean", "QuartzTask.java", 
//   	    		             TableToBean.genJavaBeanFromTableStructure(mfmt.getColumnList(), mfmt.getPackageBean(), mfmt.getBeanName()), false);
//   	     frs.saveFileContent("D:/workspace_new/WebServicesPlatForm/src/com/test/dao", "QuartzTaskDao.java", du.getDaoTemplate(mfmt),false);
//   	     frs.saveFileContent("D:/workspace_new/WebServicesPlatForm/src/com/test/service", "QuartzTaskService.java", su.getServiceTemplate(mfmt),false);
//   	     frs.saveFileContent("D:/workspace_new/WebServicesPlatForm/src/com/test/controller", "QuartzTaskController.java", cu.getControllerTemplate(mfmt),false);
//   	     frs.saveFileContent("D:/workspace_new/WebServicesPlatForm/WebContent/WEB-INF/jsp/quartzTask", "quartzTaskManager.jsp", ju.getJspTemplate(mfmt),false);
		
	     mfmt.setClassPath("D:/workspace_new/WebServicesPlatForm/src/");
	     mfmt.setJspPath("D:/workspace_new/WebServicesPlatForm/WebContent/WEB-INF/jsp/");
   	     mfmt.setTableName("TESTCODE");
	     mfmt.setTablePKSeq("TESTCODE_SEQ");
	     mfmt.setBeanName("TestCode");
	     mfmt.setPackageBean("com.test.bean");
	     mfmt.setColumnList(TableToBean.getTableStructure(mfmt.getTableName()));
	     
	     DaoTemplateUtil du=new DaoTemplateUtil();
	     ServiceTemplateUtil su=new ServiceTemplateUtil();
	     ControllerTemplateUtil cu=new ControllerTemplateUtil();
	     JspTemplateUtil ju=new JspTemplateUtil();
	     frs.saveFileContent(mfmt.getClassPath()+mfmt.getPackageBean().replace(".", "/"), mfmt.getBeanName()+".java", 
	    		             TableToBean.genJavaBeanFromTableStructure(mfmt.getColumnList(), mfmt.getPackageBean(), mfmt.getBeanName()), false);
	     frs.saveFileContent(mfmt.getClassPath()+mfmt.getPackageDao().replace(".", "/"), mfmt.getDaoName()+".java", du.getDaoTemplate(mfmt),false);
	     frs.saveFileContent(mfmt.getClassPath()+mfmt.getPackageService().replace(".","/"), mfmt.getServiceName()+".java", su.getServiceTemplate(mfmt),false);
	     frs.saveFileContent(mfmt.getClassPath()+mfmt.getPackageConlroller().replace(".","/"), mfmt.getControllerName()+".java", cu.getControllerTemplate(mfmt),false);
	     frs.saveFileContent(mfmt.getJspPath()+StringUtil.getFirstLow(mfmt.getBeanName()), mfmt.getJspName()+".jsp", ju.getJspTemplate(mfmt),false);
		
	 }
}
